package org.zwd.computePrice.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBUtils {
	
	private static String url="jdbc:mysql://localhost:3306/crabprice";  
    private static String user="root";  
    private static String password="";  
   
    static  
    {  
        try  
        {  
            Class.forName("com.mysql.jdbc.Driver");  
        }  
        catch(ClassNotFoundException e)  
        {  
            throw new ExceptionInInitializerError(e);  
        }  
    }  
    public static Connection getConnection() throws SQLException  
    {  
        return DriverManager.getConnection(url, user, password);  
    }  
	public static void free(ResultSet rs,PreparedStatement  pstmt,Connection conn){
		
		try {
			if(rs != null)
			rs.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		finally {
			try {
				if(pstmt != null)
					pstmt.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
			finally {
				try {
					if(conn != null)
						conn.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		
	}
}
